package com.example.woke;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.zhongcai.online.R;

public class UnionPayBindActivity extends AppCompatActivity {

	private static final int OPEN_DEFAULT_WEB = 88;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate (savedInstanceState);
		setContentView (R.layout.activity_union_pay_bind);
		findViewById (R.id.avhtml_image_back).setOnClickListener (new View.OnClickListener () {
			@Override
			public void onClick(View v) {
				finish ();
			}
		});
		WebView mWebView = (WebView) findViewById (R.id.webView);
		mWebView.setWebChromeClient (new WebChromeClient ());
		mWebView.setWebViewClient (new WebViewClient () {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				if (url.contains ("activateFrontCallBack")) {
					Toast.makeText (UnionPayBindActivity.this, "成功开通", Toast.LENGTH_SHORT).show ();
					finish ();
				}
				view.loadUrl (url);
				return false;
			}
		});
		WebSettings mSettings = mWebView.getSettings ();
		mSettings.setJavaScriptEnabled (true);
		mSettings.setDefaultTextEncodingName ("UTF-8");
		mSettings.setSupportZoom (true);
		mSettings.setUseWideViewPort (true);
		mSettings.setLayoutAlgorithm (WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
		mSettings.setDomStorageEnabled (true);
		mSettings.setDatabaseEnabled (true);
		mSettings.setLoadWithOverviewMode (true);
		mSettings.setJavaScriptCanOpenWindowsAutomatically (true);
		mSettings.setAllowFileAccess (true);
		mSettings.setAppCacheEnabled (true);
		mSettings.setSaveFormData (false);
		mSettings.setLoadsImagesAutomatically (true);


		Intent intent = getIntent ();
		if (intent != null) {
			String html = intent.getStringExtra ("html");
			Log.e ("银联绑卡", "----" + html);
			if (! TextUtils.isEmpty (html)) {
				mWebView.loadDataWithBaseURL (null, html, "text/html", "utf-8", null);
			} else {
				finish ();
			}
		}


	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult (requestCode, resultCode, data);
		if (requestCode == OPEN_DEFAULT_WEB && requestCode == RESULT_OK) {
			finish ();
		}
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed ();
		finish ();
	}
}
